home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13630 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: my program has a mind of its own (no really)
  5. Date: Tue, 09 Apr 96 11:55:31 GMT
  6. Organization: none
  7. Message-ID: <829050931snz@genesis.demon.co.uk>
  8. References: <sbb-0904960305370001@ts13-06.upenn.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <sbb-0904960305370001@ts13-06.upenn.edu>
  15.            sbb@eniac.seas.upenn.edu "Steve Bronstein" writes:
  16.  
  17. >I am writing a program (with cc as compiler) which has a number of arrays,
  18. >which I have been verry careful to initialize with values, to avoid
  19. >segmentation faults.
  20.  
  21. Are you talking about arrays of pointers here? What did you initialise
  22. the arrays with and how are you using them? In short post some code so we
  23. can see what you are actually doing.
  24.  
  25.  The main part of the program is a loop beginning with
  26. >an fgets statement to read in the next line from a file. Under certain
  27. >circumstances, the program returns "Segmentation Fault" just as it reaches
  28. >the beginning of this loop. When I put it a printf statement right before
  29. >the loop to see how far it actually got, it worked. 
  30.  
  31. You've done something bad with pointers e.g. used an uninitialised one,
  32. dereferenced one that doesn't point to a writable object or gone out of
  33. bounds on pointer arithmetic.
  34.  
  35. >printf("something\n");
  36. >
  37. >When I removed "something", leaving just
  38. >
  39. >printf("\n");
  40. >
  41. >it gave me a segmentation fault again. I tried the same tactic at the
  42. >beginning of the loop, and found that the program worked with a long word
  43. >in the printf statement, but not a short word.
  44.  
  45. Slight variations of the layout of memory may mask the problem but it is
  46. still there.
  47.  
  48. -- 
  49. -----------------------------------------
  50. Lawrence Kirby | fred@genesis.demon.co.uk
  51. Wilts, England | 70734.126@compuserve.com
  52. -----------------------------------------
  53.